function dyhbAlert( sContent,sTitleText ) {

   if( sTitleText=='' || sTitleText==undefined )
      sTitleText = D.L( 'DoYouHaoBaby 消息框' );

   var options = {

       buttons: {
          accept: {
             content: "<div class='doyouhaobaby-dialog-button-label' >"+D.L( '确定' )+"</div>",
             onclick: function(){

                 dialogInstance.DispatchEvent("onaccept") && dialogInstance.close();
             }
          }
       },
      titleText: sTitleText,
	  top:'30%',
	  left:'30%',
	  height: 100,
      width: 300,
      modal: true,
      draggable: true,
      contentText: "<div class='doyouhaobaby-dialog-img'></div><div class='doyouhaobaby-dialog-text'>"+sContent+"</div>",
      type: "alert",
      autoRender: true
   };
   var dialogInstance = new Dyhb.ui.Dialog(options);
   dialogInstance.open();
}


function dyhbConfirm( sContent,confrim_accept,sTitleText ) {

	 if( sTitleText=='' || sTitleText==undefined )
         sTitleText = D.L( 'DoYouHaoBaby 确认框' );

     var options = {

         buttons: {
              accept: {content: "<div class='doyouhaobaby-dialog-button-label'>"+D.L( '确定' )+"</div>",

                  onclick:  function(){
				  
				     try	{(confrim_accept).apply(this,[dialogInstance]);}
				     catch (e){}
				  } 
              },

             cancel: {content: "<div class='doyouhaobaby-dialog-button-label'>"+D.L( '取消' )+"</div>",

			     onclick: function() {

                     dialogInstance.DispatchEvent("oncancel") && dialogInstance.close();
                 }
             }
        },

        titleText: sTitleText,
		top:'30%',
	    left:'30%',
        height: 100,
        width: 300,
        modal: true,
        draggable: true,
        autoRender: true,
        contentText: sContent
    };
    dialogInstance = new D.ui.Dialog(options);
    dialogInstance.open();
}

var selectRowIndex = Array();

//编辑
function edit(id){
	var keyValue;
	if (id){
		keyValue = id;
	}else {
		keyValue = getSelectValue();
	}
	if (!keyValue){
		dyhbAlert( D.L( '请选择编辑项！' ) );
		return false;
	}
	location.href =  URL+"/edit/id/"+keyValue;
}

//禁用
function forbid(id){
	location.href = URL+"/forbid/id/"+id;
}

//恢复
function resume(id){
	location.href = URL+"/resume/id/"+id;
}

function view(id){
	location.href = URL+"/view/id/"+id;
}

function add(id){
	if (id)
	{
		 location.href  = URL+"/add/id/"+id;
	}else{
		 location.href  = URL+"/add/";
	}
}

function foreverdel(id){
	var keyValue;
	if (id){

		keyValue = id;
	}

	else {

		keyValue = getSelectValues();
	}
	if (!keyValue){

		dyhbAlert( D.L( '请选择删除项！' ) );
		return false;
	}

	dyhbConfirm( D.L( '确实要永久删除选择项吗？' ),function( dialogInstance ){

       dialogInstance.DispatchEvent("onaccept") && dialogInstance.close();
	   Dyhb.AjaxSend( URL+"/foreverdelete/","id="+keyValue+'&ajax=1','',completeDelete );
	} );
}

function completeDelete(data,status){
	if (status==1){
	var Table = D.$('checkList');
	var len	=	selectRowIndex.length;
	if(len==0){
		window.location.reload();
	}
	for (var i=len-1;i>=0;i-- ){

		//删除表格行
		Table.deleteRow(selectRowIndex[i]);
	}
	   selectRowIndex = Array();
	}
}

function getSelectValue(){
	var obj = document.getElementsByName('key');
	var result ='';
	for (var i=0;i<obj.length;i++)
	{
		if (obj[i].checked==true)
				return obj[i].value;

	}
	return false;
}

function getSelectValues(){
	var obj = document.getElementsByName('key');
	var result ='';
	var j= 0;
	for (var i=0;i<obj.length;i++){
		if (obj[i].checked==true){
				selectRowIndex[j] = i+1;
				result += obj[i].value+",";
				j++;
		}
	}
	return result.substring(0, result.length-1);
}

function child(id){
	location.href = URL+"/index/node_parentid/"+id;
}

function app(id){
	location.href = URL+"/app/group_id/"+id;
}

function group(id){
	location.href = URL+"/index/group_id/"+id;
}

function user(id){
	location.href = URL+"/user/id/"+id;
}

function cache(){
	DyhbAjax.send(URL+'/cache','ajax=1');
}

function sort(id){
	var keyValue;
	keyValue = getSelectValues();
	location.href = URL+"/sort/sort_id/"+keyValue;
}

function sortBy (field,sort){
	location.href = SORTURL+"/order_/"+field+"/sort_/"+sort;
}


function clickToInput( field,id ){

    var idObj = $('#'+field+'_'+id);

    if($('#'+field+'_input_'+id).attr("type") == "text"){return false;}

	var name = $.trim(idObj.html());

	var m = $.trim(idObj.text());

	idObj.html("<input type='text' value='"+name+"' class='field' id='"+field+"_input_"+id+"' title='"+D.L( '点击修改值' )+"' >");

	$('#'+field+'_input_'+id).focus();

	$('#'+field+'_input_'+id).blur( function () {
	    var n = $.trim($(this).val());
	    if(n != m && n != ""){

	        Dyhb.AjaxSend(URL+'/input_change_ajax','ajax=1&input_ajax_id='+id+'&input_ajax_val='+$('#'+field+'_input_'+id).val()+'&input_ajax_field='+field,'',clickToInputComplete);
	    }

		else{

		    $(this).parent().html(name);
	    }

	});
}

function clickToInputComplete(data,status){
    if(status==1){
        $('#'+data.id).html(data.value);
    }
}


function updateSeccode() {

    if( Dyhb.$( "seccodeImage" ).innerHTML=='' ){

        D.SetStyle("seccodeImage", "display", "block");
		Dyhb.$( "seccodeImage" ).innerHTML=D.L( '验证码正在加载中...');
	}
	var timenow = new Date().getTime();
	Dyhb.$( "seccodeImage" ).innerHTML ='<img id="seccode" onclick="updateSeccode()" src="' + URL+'/seccode/update/' + timenow + '"  style="cursor:pointer" title="'+D.L( '单击图片换个验证码')+'"  alt="'+D.L( '验证码正在加载中...')+'" />';
}


function checkSeccode( sTarget ){

   Dyhb.Ajax.Dyhb.UpdateTips	=	D.L( '验证码校验中...');

   var sSeccode = D.$( 'seccode' ).value;

   if( sSeccode=='' ){

       D.$( 'seccodeMessage' ).innerHTML=D.L( ' 验证码不能为空');
	   return;
   }
   Dyhb.AjaxSend( URL+'/check_seccode','ajax=1&seccode='+sSeccode,sTarget,check_handle );

   Dyhb.Ajax.Dyhb.UpdateTips	=	D.L( '处理中...');
}

function check_handle( data,status ){

   if (status==1){

       D.$( 'seccodeMessage' ).innerHTML=D.L( ' 验证码正确');
   }
}

function checkAll(str){
	var i;
	var	inputs = document.getElementById(str).getElementsByTagName("input");
	for	(i=1; i < inputs.length; i++){
		inputs[i].checked=inputs[0].checked;
	}
}
